package com.mstanford.movie.utils;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public final class DBUtil {

	private DBUtil() {}
	
	public final static Connection getConnection() {
		
		try {
			Class.forName(ConstantUtil.DRIVER);
			return DriverManager.getConnection(ConstantUtil.URL, ConstantUtil.USER, ConstantUtil.PASSWORD);
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
		return null;
	}
	
	public final static void close(ResultSet rs, PreparedStatement ps, Connection con) {
		
		try {
			if(rs != null) {
				rs.close();
				rs = null;
			}
			
			if(ps != null) {
				ps.close();
				ps = null;
			}
			
			if(con != null) {
				con.close();
				con = null;
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
}